﻿Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Controls.Primitives
Imports System.ComponentModel
Imports OMANE.Modules.TauxGarantis.ViewModels

Namespace Views
    Public Class ViewGarantiesIncapInval

        Private Sub VariableStyle_PreviewMouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
            DragDrop.DoDragDrop(sender, sender, DragDropEffects.Copy)
        End Sub

        Private Sub DataGrd_Drop(ByVal sender As Object, ByVal e As System.Windows.DragEventArgs)
            If variablesLst.SelectedItems.Count < 2 Then
                Dim lvitem As ListViewItem = e.Data.GetData(GetType(ListViewItem))
                Dim vm As ViewModels.ViewModelGarantiesIncapInval = DataContext
                vm.CurrentSegmentableValue.AddVar(lvitem.DataContext.Description)
            Else
                Dim func = Function(elt)
                               Return elt.Description.ToString()
                           End Function
                Dim vm As ViewModels.ViewModelGarantiesIncapInval = DataContext
                Dim q = From elt In variablesLst.SelectedItems
                        Select func(elt)
                vm.CurrentSegmentableValue.AddVar(q.AsEnumerable())
            End If
        End Sub

        Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
            Dim bt As Button = sender
            Dim vm As ViewModels.ViewModelGarantiesIncapInval = DataContext
            Dim q = From elt In CType(vm.CurrentSegmentableValue.Table, DataTable).Columns
                    Where elt.ColumnName = bt.DataContext
                    Select elt.Caption
            vm.CurrentSegmentableValue.RemoveVar(q.FirstOrDefault())
        End Sub

        Private Sub ToggleButton_Unchecked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
            'TODO: Add event handler implementation here. 
            Dim tb As ToggleButton = sender
            If tb.DataContext IsNot Nothing Then
                Dim vm As ViewModels.ViewModelGarantiesIncapInval = TryCast(DataContext, ViewModelGarantiesIncapInval)
                If vm IsNot Nothing Then
                    vm.CurrentSegmentableValue = tb.DataContext
                End If
            End If
        End Sub


        Private Sub RadioButton_Checked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
            Dim tb As RadioButton = sender
            If tb.DataContext IsNot Nothing Then
                Dim vm As ViewModels.ViewModelGarantiesIncapInval = TryCast(DataContext, ViewModelGarantiesIncapInval)
                If vm IsNot Nothing Then
                    vm.CurrentSegmentableValue = tb.DataContext
                End If
            End If
        End Sub
    End Class
End Namespace